/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

// 设置密码校验规则
const checkPassword = (rule, value, callback) => {
  if (window.boxType === "edit") {
    return callback();
  }
  if (!value) {
    callback(new Error("请输入密码"));
  } else {
    callback();
  }
};

// 设置手机号的验证规则
const checkPhone = (rule, value, callback) => {
  if (!value) {
    callback(new Error("请输入联系方式"));
  } else {
    const reg = /^1[3|4|5|7|8][0-9]\d{8}$/;
    if (reg.test(value)) {
      callback();
    } else {
      return callback(new Error("请输入正确的电话"));
    }
  }
};

export const tableOption = {
  border: true,
  index: true,
  indexLabel: "序号",
  stripe: true,
  searchMenuSpan: 6,
  editBtn: false,
  labelWidth: "200",
  searchSpan: 7,
  delBtn: false,
  align: "center",
  addBtn: false,
  column: [{
      fixed: true,
      label: "用户名",
      prop: "username",
      search: true,
      editDisabled: true,
      span: 24,
      rules: [{
        required: true,
        message: "请输入用户名"
      }]
    },
    {
      label: "姓名",
      prop: "name",
      span: 24,
      search: true,
      rules: [{
        required: true,
        message: "请输入姓名",
        trigger: "blur"
      }],
    },
    {
      label: "密码",
      prop: "password",
      type: "password",
      editDisplay: false,
      addDisplay: false,
      hide: true,
      span: 24,
      rules: [{
        validator: checkPassword,
        trigger: "blur"
      }]
    },
    {
      label: "角色",
      prop: "role_type",
      span: 24,
      rules: [{
        required: true,
        message: "请选择角色",
        trigger: "blur"
      }],
      type: "select",
      dicFlag: true,
      dicUrl: process.env.VUE_APP_BASE_API + "/admin/role/listAll",
      dicFormatter: res => {
        return (res.data || []).map(o => ({
          label: o.roleName,
          value: o.id
        }));
      },
      props: {
        label: "label",
        value: "value"
      },
    }, {
      label: "最近登录时间",
      prop: "gmt_last_login",
      editDisplay: false,
      addDisplay: false,
      span: 24
    },
    {
      label: "创建时间",
      prop: "create_time",
      editDisplay: false,
      addDisplay: false,
      span: 24
    },
    {
      label: "正常/冻结",
      prop: "status",
      type: "radio",
      slot: true,
      editDisplay: false,
      addDisplay: false,
      span: 24,
      rules: [{
        required: true,
        message: "请选择状态",
        trigger: "blur"
      }],
    },
  ]
};



export const companyOption = {
  border: true,
  index: true,
  indexLabel: "序号",
  stripe: true,
  searchMenuSpan: 6,
  editBtn: false,
  labelWidth: "200",
  searchSpan: 7,
  delBtn: false,
  align: "center",
  addBtn: false,
  column: [{
      fixed: true,
      label: "用户名",
      prop: "username",
      search: true,
      editDisabled: true,
      span: 24,
      rules: [{
        required: true,
        message: "请输入用户名"
      }]
    },
    {
      label: "企业名称",
      prop: "name",
      span: 24,
      search: true,
      rules: [{
        required: true,
        message: "请输入姓名",
        trigger: "blur"
      }],
    },
    {
      label: "手机号",
      prop: "phone",
      span: 24
    },
    {
      label: "密码",
      prop: "password",
      type: "password",
      editDisplay: false,
      addDisplay: false,
      hide: true,
      span: 24,
      rules: [{
        validator: checkPassword,
        trigger: "blur"
      }]
    },
    {
      label: "最近登录时间",
      prop: "gmt_last_login",
      editDisplay: false,
      addDisplay: false,
      span: 24
    },
    {
      label: "创建时间",
      prop: "create_time",
      editDisplay: false,
      addDisplay: false,
      span: 24
    },
    {
      label: "正常/冻结",
      prop: "status",
      type: "radio",
      slot: true,
      editDisplay: false,
      addDisplay: false,
      span: 24,
      rules: [{
        required: true,
        message: "请选择状态",
        trigger: "blur"
      }],
    },
  ]
};

